<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%-- 修改用户信息 --%>
<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">

<title>采购单确认</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<%-- 引用layui.css --%>
<link rel="stylesheet" type="text/css" href="js/layui/css/layui.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>css/common.css" />
<script type="text/javascript" src="<%=basePath%>js/layui/layui.js"></script>
<script type="text/javascript" src="js/common/jquery-1.8.3.min.js"></script>
</head>

<body>
					
                   <table class="layui-table layui-form" lay-filter="popedomLay">
                     <thead>
                       <tr>
                         <!-- <th>
                           <input type="checkbox" name=""  lay-skin="primary">
                         </th> -->
                         <th>商品Id</th>
                         <th>采购单号</th>
                         <th>商品名称</th>
                         <th>所属服务点</th>
                         <th>商品类型</th>
                         <th>采购数量</th>
                         <th>实际到货数量</th>
                     </thead>
                     <tbody>
                     <c:if test="${empty tvptList }">
                       	<p style="color:gray;text-align:center;">网络请求异常</p>
                      </c:if>
                       <c:if test="${not empty tvptList }">
                       	<c:forEach items="${tvptList }" var="list" varStatus="status">
                      		<tr>
                       			<!-- <td>
                              		 <input type="checkbox" name="id" value="1"   lay-skin="primary"> 
                            	</td> -->
                             	<td name="goodsId">${list.goodsId}</td>
                            	<td >${list.purchaseId}</td>
                            	<td>${list.goodsName}</td>
                            	<td>${list.areaName}</td>
                           		<c:if test="${list.goodsType==0}">
                           			<td>正品	</td>
                           		</c:if>
                           		<c:if test="${list.goodsType==1}">
                           			<td>打折	</td>
                           		</c:if>
                           		<c:if test="${list.goodsType==2}">
                           			<td>体验	</td>
                           		</c:if>
                           		<c:if test="${list.goodsType==3}">
                           			<td>积分兑换	</td>
                           		</c:if>
                           		<c:if test="${list.goodsType==4}">
                           			<td>打包	</td>
                           		</c:if>
                            	<td>${list.purchaseNum}</td>
                            	<td><input type="text" name="realNum" ></td>
                            	
                       		</tr>
                       	</c:forEach>
                       	<input type="hidden" name="purchaseGoodsId" value="${tvptList[0].purchaseGoodsId }">
                       	<input type="hidden" name="servicePointId" value="${tvptList[0].servicePointId }">
                       	<input type="hidden" name="Id" value="${tvptList[0].purchaseId }">
                       </c:if>
                 	  </tbody>
                   </table>
                   <hr class="layui-bg-gray">
						<div class="layui-form-item">
							<div class="layui-input-block">
								<button class="layui-btn" lay-submit lay-filter="confirm" id="confirm">确认</button>
								<button  id="closeBtn" class="layui-btn layui-btn-primary">取消</button>
							</div>
						</div>
 </div>
	
	<script type="text/javascript" src="js/layui/layui.js"></script>
	<script type="text/javascript">
	layui.config({
        base: "<%=basePath%>/js/common/"
    }).use(["common",  "layer",  "table"], function(){
			var layer = layui.layer;
			var table = layui.table;
			layui.common.init();
			//监听提交  添加
			
			$("#confirm").click(function(){
				 
				var servicePointId = $("input[name='servicePointId']").val();
				var purchaseGoodsId = $("input[name='purchaseGoodsId']").val();
				var purchaseId=$("input[name='Id']").val();
				//到货数量
				var realNum=new Array();//创建一个数组装输入框中的数据
				$("input[name='realNum']").each(function(){
			      	  realNum.push($(this).val());
					});
				//与仓库对应的goodsId数组
				var goodsId = new Array();
				$("td[name='goodsId']").each(function(){
					goodsId.push($(this).html());
					});
				
				 $.ajax({
	                    type:"post",
	                    url:'CGDH/updTvp.do',
	                    data:{
	                    	"purchaseId": purchaseId,
	                    	"purchaseGoodsId": purchaseGoodsId,
	                    	"realNum": realNum,
	                    	"goodsId": goodsId,
	                    	"servicePointId": servicePointId
	                    },
	                    traditional: true,//这里设置为true,为的是向后台传数组
	                    dataType:"json",
	                    success:function(json){
	                    	console.log(json)
	                        if(json.statusCode == 200){
	                        	var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
	                            parent.layer.close(index);//再执行关闭   
	                            parent.layer.msg(json.message, {icon: 6,time: 2000});
	                        } else{
	                        	layer.msg(json.message, {icon: 5,time: 2000});
	                        }
	                    }
	                });
				
			});
			
            /* table.on('submit(confirm)', function(data){
                layer.msg(JSON.stringify(data.field));
                $.ajax({
                    type:"post",
                    url:'CGDH/updTvp.do',
                    data:data.field,
                    dataType:"json",
                    success:function(json){
                       
                        if(json.statusCode == 200){
                        	var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            parent.layer.msg(json.message, {icon: 6,time: 2000});
                        } else{
                        	layer.msg(json.message, {icon: 5,time: 2000});
                        }
                    }
                });
                return false;
            }); */
			
			//关闭当前弹出层
            $(document).on('click', '#closeBtn',
                    function() {
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.location.reload();//刷新父页面，注意一定要在关闭当前iframe层之前执行刷新
                        parent.layer.close(index); //再执行关闭
                    });
    
    });


	</script>
</body>
</html>
